import requests
from bs4 import BeautifulSoup
import random
from datetime import datetime

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
}

url = 'https://www.meishij.net/fenlei/recai/'

ccid = requests.get(url,headers=headers)

ccid.encoding = "UTF-8"

dada = BeautifulSoup(ccid.text,'html.parser')

li = dada.find_all("div",class_='list_s2_item')
# print('>>>>>',li)
for i in li:
    # 提取图片
    img_name = str(i.find('div',class_='imgw').a.get('style')).split('(')[1].split(')')[0]
    # 生成文件名
    i_name = str(random.randint(10000,99999)) + datetime.strftime(datetime.now(),'%Y%m%d%M%H%S') + '.jpg'
    # 重新请求
    img_get = requests.get(img_name)
    with open('../static/' + i_name,'wb') as f:
        f.write(img_get.content)
    print('>>',img_name)
    # 提取标题
    title = i.find('a',class_='list_s2_item_info').strong.string
    pei = i.find('a',class_='list_s2_item_info').span.string









